package com.jcsz.gulimall.search.controller;

import com.jcsz.gulimall.search.service.MallSearchService;
import com.jcsz.gulimall.search.vo.SearchParam;
import com.jcsz.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @className: SearchController
 * @author: 一把Po吉他
 * @date: 2022/11/3 9:23
 * @version: 1.0
 **/
@Controller
public class SearchController {

    @Autowired
    private MallSearchService searchService;

    @GetMapping("list.html")
    public String list(SearchParam param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        SearchResult result = searchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
